<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>表格查询</title>
    <#assign base=request.contextPath  />
    <base id="base" href="${base}">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, adminUser-scalable=0">
    <link rel="stylesheet" href="${base}/static/win10/component/layui/css/layui.css" media="all">
    <script>
        var base = "${base}";
    </script>
</head>
<body>
<br>


<div class="demoTable" style="margin-left: 15px;">
    <form class="layui-form " action="">
        <div class="layui-form-item">
            <label>用户名</label>
            <div class="layui-inline">
                <input class="layui-input" name="uName" id="uName" autocomplete="off">
            </div>


            <label>位置名字</label>
            <div class="layui-inline">
                <input class="layui-input" name="locationName" id="locationName" autocomplete="off">
            </div>


            <div class="layui-inline">
                <input class="layui-input" name="y" id="y" autocomplete="off">
            </div>
            <label>年</label>

            <div class="layui-inline">
                <input class="layui-input" name="m" id="m" autocomplete="off">
            </div>
            <label>月</label>

            <div class="layui-inline">
                <input class="layui-input" name="d" id="d" autocomplete="off">
            </div>
            <label>日</label>
            <button type="button" class="layui-btn" data-type="reload" id="sech">
                <i class="layui-icon layui-icon-search">搜索</i>
            </button>
        </div>
    </form>
</div>
<table class="layui-hide" id="test" lay-filter="test"></table>
<script type="text/html" id="toolbarDemo">


    <form class="layui-form " action="">
        <div class="layui-form-item" style="margin-left: 15px;">
            <div class="layui-btn-group">
                <button type="button" class="layui-btn" lay-event="editLocal">修改地点与结算状态</button>
              <#--  <button type="button" class="layui-btn" lay-event="edit">编辑</button>-->
                 <#--   <button type="button" class="layui-btn" lay-event="editStatus">更改结算状态</button>-->
            </div>
        </div>



    </form>
</script>

<script src="${base}/static/win10/component/layui/layui.js?t=1"></script>
<script src="${base}/static/win10/js/jquery-1.8.3.min.js?t=1"></script>
<script>
    layui.use(['table'], function () {
        var table = layui.table;
        table.render({
            skin: 'line' //行边框风格
            , even: true //开启隔行背景
            , elem: '#test'
            , url: base + '/app/sign/findSignByPage'
            , toolbar: '#toolbarDemo'
            , cols: [[
                {type: 'checkbox'},
                {field: 'uName', title: '用户名'},
                {field: 'y', title: '年'},
                {field: 'm', title: '月'},
                {field: 'd', title: '日'},
                {field: 'price', title: '补助金额'},
                {field: 'isPay', title: '是否已结算', templet: function(val){
                        if(val.isPay==1){
                            return "是";
                        }
                         return  "否"

                    }},


                {field: 'locationName', title: '位置名字', templet: function(val){
                        if(val.locationName==null){
                            return "无";
                        }
                        try{
                            return JSON.parse(val.locationName).address
                        }catch (e) {
                            return  val.locationName
                        }

                    }}
            ]]
            , page: true
            , id: 'testReload'
            ,limits:[10,20,50,100,200,500,1000,2000,5000,10000]
        });
        //搜索
        var $ = layui.$, active = {
            reload: function () {
                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: {
                        locationName: $("#locationName").val(),
                        fileName: $("#fileName").val(),
                        y: $("#y").val(),
                        m: $("#m").val(),
                        d: $("#d").val(),
                        latitude: $("#latitude").val(),
                        longitude: $("#longitude").val(),
                        userId: $("#userId").val(),
                        isPm: $("#isPm").val(),
                        uName: $("#uName").val()
                    }
                }, 'data');
            }
        };
        $('.demoTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });


        //头工具栏事件
        table.on('toolbar(test)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id); //获取选中行状态
            var data = checkStatus.data;  //获取选中行数据
            switch (obj.event) {
                case 'add':
                    //请继续补充以下逻辑
                    window.location.href = base + "/app/sign/addSignHtml"
                    break;
                case 'edit':
                    //请继续补充以下逻辑
                    window.location.href = base + "/app/sign/editSignHtml?id=" + data[0].id
                    break;
                case 'editLocal':
                    if (data.length === 0) {
                        layer.alert("请选择一条数据")
                        return;
                    }
                    var ids=[];
                    for (var i = 0; i <data.length ; i++) {
                    if(data[i].isPay==1){
                        layer.alert("包含已结算过的签到记录，请重新选择")
                        return;

                    }
                     ids.push(data[i].id);
                    }
                    layer.open({
                        type: 2,
                        content: '${base}/app/sign/editSignLocal?ids='+ids.toString(),
                        area: ['400px', '450px'],
                        success:function(layero, index){
                            //弹窗后  把窗Dom赋值给全局
                            var  iframeWin = window[layero.find('iframe')[0]['name']];
                            iframeWin.$("#submit").on("click",function () {
                                if( iframeWin.$("#locals").val().length<1){
                                    layer.msg("请选择地点")
                                    return;
                                }

                                var formData={
                                    idsStr: iframeWin.$("#ids").val(),
                                    localName: iframeWin.$("#locals").val(),
                                    isPay: iframeWin.$("#isPay").val()
                                };
                                $.ajax({
                                    type: "GET",
                                    url: base + "/app/sign/editSignLocalAjax",
                                    data:formData,
                                    success: function (data) {
                                        if (data.code === 200) {
                                            if (data.code === 200) {
                                                layer.close(index); //如果设定了yes回调，需进行手工关闭
                                                $("#sech").click();
                                            }
                                        }
                                    }
                                });

                            })
                        }
                    });
                    //请继续补充以下逻辑
                 //   window.location.href = base + "/app/sign/editSignHtml?id=" + data[0].id
                    break;
                case 'show':
                    if (data.length === 0) {
                        layer.alert("请选择一条数据")
                        return;
                    }
                    //请继续补充以下逻辑
                    window.location.href = base + "/app/sign/showSignHtml?id=" + data[0].id
                    break;
                case 'del':
                    if (data.length === 0) {
                        layer.alert("请选择一条数据")
                        return;
                    }
                    layer.confirm('真的要删除吗?', function (index) {
                        $.ajax({
                            type: "POST",
                            url: base + '/app/sign/delSign',
                            data: {"id": data[0].id},
                            success: function (data) {
                                if (data.code === 200) {
                                    layer.msg(data.message)
                                    setTimeout(function () {
                                        window.location.reload();
                                    }, 500)
                                } else {
                                    layer.msg(data.message)
                                }
                            }
                        });
                    });
                    break;
            }
            ;
        });
    })
</script>
</body>
</html>